close all
clear cll
clc

addpath('./0 API库函数'); % add manually the API root directory.
hfssIncludePaths('./0 API库函数');

% Antenna Parameters.
fC   = 150e6;    % Frequency of Interest.
Wv   = 3e8/fC;    % Wavelength.
L    = Wv/2;    % Antenna Length.
gapL = 5e-2;    % Antenna Gap.
aRad = 2e-2;    % Antenna Radius.

% Simulation Parameters.
fLow    = 100e6;
fHigh   = 200e6;
nPoints = 201;

% AirBox Parameters.
AirX = Wv/2 + L;    % Include the antenna length.
AirY = Wv/2; 
AirZ = Wv/2;

HFSS_Prj_Name    = [pwd, '\tmpDipole222.aedt'];
Design_Name = 'without_balun';
Setup_Name = 'Setup1';

tmpDataFile   = [pwd, '\tmpData.m'];
tmpScriptFile = [pwd, '\Open_Prj.vbs'];

% HFSS Executable Path.
hfssExePath = 'C:\Program Files\AnsysEM\v222\Win64\ansysedt.exe';

fid = fopen(tmpScriptFile, 'wt');

hfssOpenProject_R2021(fid, HFSS_Prj_Name)
hfssAnalyze_R2021(fid , Design_Name , Setup_Name)
hfssAnalyze_R2021(fid , Design_Name , Setup_Name)

ReportName = 'S Parameter Plot 1';
FileName = [ pwd , '\', 'S Parameter Plot 1'];
Type = 'csv';
hfssExportToFile_R2021(fid, ReportName, FileName, Type)

ReportName = 'VSWR Plot 1';
FileName = [ pwd , '\' , 'VSWR Plot 1'];
Type = 'csv';
hfssExportToFile_R2021(fid, ReportName, FileName, Type)

ReportName = 'S Parameter Chart 1';
FileName = [ pwd , '\' , 'S Parameter Chart 1'];
Type = 'csv';
hfssExportToFile_R2021(fid, ReportName, FileName, Type)

fclose(fid);

%     disp('Solving using HFSS...');
    hfssExecuteScript(hfssExePath, tmpScriptFile);
